<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增1')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-files-add" enctype="multipart/form-data">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">名称：</label>
                    <div class="col-sm-8">
                        <input name="filename" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">文件：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="fileContent">
                        <div class="file-loading">
                            <input class="form-control file-upload" id="fileContent" name="files" type="file" multiple>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "system/files"
        $("#form-files-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var form = $('#form-files-add')[0];
                var formData = new FormData(form);

                $.ajax({
                    url: prefix + "/batchAdd",
                    type: "POST",
                    data: formData,
                    processData: false,
                    contentType: false,
                    success: function (result) {
                        $.operate.successCallback(result);
                    },
                    error: function (xhr) {
                        $.modal.alertError(xhr.responseText || "上传失败");
                    }
                });
            }
        }

        $(".file-upload").fileinput({
            showUpload: false,
            showCaption: true,
            browseClass: "btn btn-primary",
            maxFileCount: 20,
            autoReplace: false,
            msgFilesTooMany: "选择的文件数量超过限制！"
        });
    </script>
</body>
</html>